package com.wjb.service.Impl;

import com.wjb.mapper.CouponMapper;
import com.wjb.pojo.dto.CouponDto;
import com.wjb.pojo.entity.Coupon;
import com.wjb.service.CouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author : 王济彬
 * @date: 2025/5/24 - 05 - 24 - 23:48
 * @Description: com.wjb.service.Impl
 * @version: 1.0
 */
@Service
public class CouponServiceImpl implements CouponService {

    @Resource
    private CouponMapper couponMapper;

    @Override
    public boolean createCoupon(Coupon coupon) {
        return couponMapper.insertCoupon(coupon.getCouponId(),coupon.getIsUse(),coupon.getEndTime(),coupon.getDesignatedGoodId(),coupon.getId());
    }

    @Override
    public boolean hasCoupon(int couponid) {
        return couponMapper.hasCoupon(couponid)>0;
    }

    @Override
    public boolean useCoupon(int id) {
        if(getCouponIsUse(id)){
            System.out.println("可以使用优惠卷");
            return couponMapper.useCoupon(id);
        }else{
            System.out.println("优惠卷已使用");
            return false;
        }
    }

    @Override
    public boolean getCouponIsUse(int id) {
        if("0".equals(couponMapper.getCouponIsUse(id))){
            System.out.println("优惠卷有效");
            return true;
        }else{
            return false;
        }
    }


}
